public class Solution1027 {
    public int longestArithSeqLength(int[] nums) {
        int[][] f=new int[nums.length][1005];
        int ans=0;
        for (int i=0;i<nums.length;i++){
            for (int j=i+1;j<nums.length;j++){
                int t=nums[j]-nums[i]+500;
                f[j][t]=Math.max(f[j][t],f[i][t]+1);
                ans=Math.max(ans,f[j][t]);
            }
        }
        return ans+1;
    }

    public static void main(String[] args) {
        System.out.println(new Solution1027().longestArithSeqLength(new int[]{20,1,15,3,10,5,8}));
    }
}
